package com.sjc.html2md;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.io.IOException;
import java.util.Iterator;

public class GetMulu {
    public static void main(String[] args) throws IOException {
        String url = "https://gate.lagou.com/v1/neirong/kaiwu/getCourseLessons?courseId=690";
        String htmlJson = Html2Markdown.getHtmlJson(url);
        JSONObject jsonObject = JSONObject.parseObject(htmlJson);
        JSONObject content = jsonObject.getJSONObject("content");
        JSONArray courseSectionList = content.getJSONArray("courseSectionList");
        for (Iterator<Object> iterator = courseSectionList.iterator(); iterator.hasNext(); ) {
            JSONObject next = (JSONObject) iterator.next();
            System.out.println(next.getString("sectionName"));

            JSONArray courseLessons = next.getJSONArray("courseLessons");
            for (Iterator<Object> courseIter = courseLessons.iterator(); courseIter.hasNext(); ) {
                JSONObject courseLesson = (JSONObject) courseIter.next();
                String courseName = courseLesson.getString("id") +"  -->  " + courseLesson.getString("theme");
                System.out.println(courseName);
            }
            System.out.println();
        }
    }
}
